package com.hkyl.hospital.service.impl;

import com.github.pagehelper.PageHelper;
import com.hkyl.hospital.entity.Operation;
import com.hkyl.hospital.entity.OperationExample;
import com.hkyl.hospital.entity.Sickroom;
import com.hkyl.hospital.entity.SickroomExample;
import com.hkyl.hospital.mapper.custom.CustomSickRoomMapper;
import com.hkyl.hospital.service.SickRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author gao
 * @date 2023/07/13 14:12:03
 */
@Service
@Transactional
public class SickRoomServiceImpl implements SickRoomService {
    @Autowired
    private CustomSickRoomMapper sickroomMapper;
    @Override
    public List<Sickroom> findSomeByPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Sickroom> sickrooms = sickroomMapper.findAll();
        return sickrooms;
    }

    @Override
    public int insert(Sickroom sickroom) {
        int i = sickroomMapper.insertSelective(sickroom);
        return i;
    }

    @Override
    public int delete(Integer sickroomId) {
        int i = sickroomMapper.updateIsDelete(sickroomId);
        return i;
    }

    @Override
    public int changeStatus(Integer id) {
        int i = sickroomMapper.changeStatus(id);
        return i;
    }

    @Override
    public int update(Sickroom sickroom) {
        int i = sickroomMapper.updateByPrimaryKeySelective(sickroom);
        return i;
    }

    @Override
    public List<Sickroom> search(String sickRoomCode,String nurseName ,Integer pageNumber, Integer pageSize) {
        SickroomExample sickroomExample=new SickroomExample();
        sickroomExample.or().andSickroomCodeLike("%"+sickRoomCode+"%").andNurseNameLike("%"+nurseName+"%");
        PageHelper.startPage(pageNumber,pageSize);
        List<Sickroom>sickrooms=sickroomMapper.selectByExample(sickroomExample);
        return sickrooms;
    }
}
